import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory，history模式：createWebHistory
  routes: [
    {
      path: '/',
      name: 'index',
      // component: () => import('@Project/agreement/views/index.vue'),
      meta: { title: '游成互动-用户协议' },
      redirect: '/agreement',
      children:[
        {
          path: '/agreement',
          name: 'agreement',
          component: () => import('@Project/agreement/views/index.vue'),
          meta: { title: '游成互动-用户协议' }
        },
        {
          path: '/privacy',
          name: 'privacy',
          component: () => import('@Project/agreement/views/index.vue'),
          meta: { title: '游成互动-隐私政策' }
        },
        {
          path: '/legal',
          name: 'legal',
          component: () => import('@Project/agreement/views/index.vue'),
          meta: { title: '游成互动-法律声明' }
        },
        {
          path: '/dispute',
          name: 'dispute',
          component: () => import('@Project/agreement/views/index.vue'),
          meta: { title: '游成互动-纠纷处理' }
        },
      ]
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      beforeEnter: (to, from, next) => {
        next({ name: 'index' })
      }
    }
  ]
})

router.afterEach((to, from, next) => {
  //遍历meta改变title
  if (to.meta.title) {
    document.title = to.meta.title
  }
  window.scrollTo(0, 0)
})
export default router
